<include file="Public:header" />
<div id="zoneHeader">
    <h2>广告报表</h2>
</div><!--/#zoneHeader-->
<div id="zoneBody">
    <div id="zoneBodySearch">
        <form id="formSearch" action="?m={$Think.const.MODULE_NAME}">
            <input type="hidden" name="sort" />
            <input type="hidden" name="sortdir" />

            <ul>
                <li><b>日期：</b><input type="text" name="day" class="fW100p" id="day" /></li>
                <li><b>所属计划：</b>
                    <select id="plan_id" name="plan_id">
                        <option value="">请选择</option>
                    </select>
                </li>
                <li><b>广告编号：</b><input type="text" name="ad_id" class="fW80p" /></li>
                <li><button type="button" id="as" class="btnSearch">查询</button></li>
                <li><button type="button" class="btnResetForm">清空表单</button></li>
            </ul>
        </form>
    </div><!--/#zoneBodySearch-->
    <div id="zoneBodyContent">
        <table class="table2">
            <thead>
                <tr>
                    <th>日期</th>
                    <th class="tAr"><a href="javascript:;" sort="ad_id">广告编号</a></th>
                    <th class="tAl">广告类型</th>
                    <th class="tAr"><a href="javascript:;" sort="view">浏览量</a></th>
                    <th class="tAr"><a href="javascript:;" sort="num">结算数</a></th>
                    <flag:isadmin>
                    <th class="tAr"><a href="javascript:;" sort="deduction">扣点</a></th>
                    </flag:isadmin>
                    <th class="tAr"><a href="javascript:;" sort="click">点/弹次数</a></th>
                    <th class="tAr"><a href="javascript:;" sort="ctr">CTR</a></th>
                    <th class="tAr"><a href="javascript:;" sort="r_searcher">搜</a></th>
                    <th class="tAr"><a href="javascript:;" sort="r_self">站内</a></th>
                    <th class="tAr"><a href="javascript:;" sort="r_other">站外</a></th>
                    <th class="tAr"><a href="javascript:;" sort="r_none">无来路</a></th>
                    <th class="tAr">到达数</th>
                    <th class="tAr">到达率</th>
                    <th class="tAr">二次点击</th>
                    <th class="tAr">二点率</th>
                    <th class="tAr"><a href="javascript:;" sort="p_flash">Flash</a></th>
                    <th class="tAr"><a href="javascript:;" sort="p_alexa">Alexa</a></th>
                    <th class="tAr"><a href="javascript:;" sort="p_net">net</a></th>
                    <th class="tAr"><a href="javascript:;" sort="new_user">新流量</a></th>
                    <flag:isadmin>
                    <th class="tAr"><a href="javascript:;" sort="siter_income">应付</a></th>
                    </flag:isadmin>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <volist name="page.record" id="vo">
                <tr class="tAr">
                    <td>{$Think.get.day}</td>
                    <td class="tAr"><a href="?m=Ad&search_item_1=ad_id&search_item_val_1={$vo.ad_id}&ad_id={$vo.ad_id}" target="_blank">{$vo.ad_id}</a></td>
                    <td class="tAl">{$vo.ad_id|getAdTypeCnByAdId}</td>
                    <td class="tAr">{$vo.view}</td>
                    <td class="tAr">{$vo.num}</td>
                    <flag:isadmin>
                    <td class="tAr">{$vo.deduction}</td>
                    </flag:isadmin>
                    <td class="tAr">{$vo.click}</td>
                    <td class="tAr">{:getCtr($vo['view'], $vo['num'])}</td>
                    <td class="tAr">{$vo.r_searcher}</td>
                    <td class="tAr">{$vo.r_self}</td>
                    <td class="tAr">{$vo.r_other}</td>
                    <td class="tAr">{$vo.r_none}</td>
                    <td class="tAr">{$vo.reach}</td>
                    <td class="tAr">{:getCtr($vo['num'] + $vo['deduction'], $vo['reach'])}%</td>
                    <td class="tAr">{$vo.do2_any_click}</td>
                    <td class="tAr">{:getCtr($vo['reach'], $vo['do2_any_click'])}%</td>
                    <td class="tAr">{$vo.p_flash}</td>
                    <td class="tAr">{$vo.p_alexa}</td>
                    <td class="tAr">{$vo.p_net}</td>
                    <td class="tAr">{$vo.new_user}<br />{:getCtr($vo['num'] + $vo['deduction'], $vo['new_user'])}%</td>
                    <flag:isadmin>
                    <td class="tAr">{$vo.siter_income}</td>
                    </flag:isadmin>
                    <td class="tAction">
                        <a href="?m=Ad&a=show&id={$vo.ad_id}" target="_blank">预</a>
                    </td>
                </tr>
                </volist>
            </tbody>
        </table>
    </div><!--/#zoneBodyContent-->
</div><!--/#zoneBody-->
<div id="zoneFooter">{$page|uiGetPage}</div><!--/#zoneFooter-->
<script type="text/javascript">
$(function(){
    var planId = <notempty name="Think.get.plan_id">'{$Think.get.plan_id}'<else />null</notempty>,
        day = <notempty name="Think.get.day">'{$Think.get.day}'<else />'{:date('Y-m-d')}'</notempty>,
        eventer = window;

    $('#formSearch').find('input[name=day]').datebox({
        onSelect: function(date){
            getPlanList($(this).datebox('getValue'));
        }
    });

    $(eventer).on('GET_PLAN_LIST', function(e, d) {
        var html = '<option value="">请选择</option>';

        $.each(d, function(k, v){
            html += '<option value=' + v.plan_id + '>#' + v.plan_id + ' ' + v.plan_name + '</option>';
        })

        $('#plan_id').html(html);
        $(eventer).trigger('GEN_PLAN_LIST');
    })

    $(eventer).on('GEN_PLAN_LIST', function(e, $o){
        if (planId) {
            $('#plan_id').val(planId);
        }
    })

    var getPlanList = function(day) {
        var url = '?m=PlanStats&a=apiGetPlanListByDay';

        $.getJSON(url, {day : day}, function(j) {
            if (!j.s) {
                alert(j.m);

                return false;
            }

            $(eventer).trigger('GET_PLAN_LIST', [j.d]);
        })
    }

    getPlanList(day);
})
</script>
        <include file="Public:footer" />
